lis2mdl: Add two-point temperature calibration.#114
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Adds two-point temperature calibration support to the LIS2MDL driver to align with the calibration capabilities available in other sensor drivers, and introduces mock scenario coverage for the new calibration behavior.
Changes:
- Add
_temp_gain,_temp_offset, and_temp_base_offsetand apply them inread_temperature_c(). - Add
calibrate_temperature(ref_low, measured_low, ref_high, measured_high)for two-point gain/offset calibration. - Extend LIS2MDL mock scenarios with offset and two-point calibration tests.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| lib/lis2mdl/lis2mdl/device.py | Introduces temperature gain/offset calibration and updates temperature conversion pipeline. |
| tests/scenarios/lis2mdl.yaml | Adds mock scenarios validating single-point offset and two-point calibration behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Contributor
Author
|
Addressed Copilot review:
|
|
🎉 This PR is included in version 0.0.2 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
calibrate_temperature()method for two-point calibration (gain + offset)_temp_base_offset = 25°C) from user calibration (_temp_gain,_temp_offset)set_temp_offset()to reset gain to 1.0The LIS2MDL has a specific temperature model:
T = base_offset + raw / sensitivitywherebase_offsetdefaults to 25°C (empirical, not guaranteed by datasheet). The calibrationapplies on top:
T_cal = gain * T_factory + offset.Closes #113
Test plan
Mock tests (CI)
python3 -m pytest tests/ -k "lis2mdl and mock" -vHardware tests (STeaMi board)
python3 -m pytest tests/ --port /dev/ttyACM0 -k "lis2mdl and hardware" -s -vruff checkpassesTest results